const gulp = require("gulp");
const CleanCss = require("gulp-clean-css");
const browserSync = require('browser-sync').create();
//引入gulp-sass
const sass=require("gulp-sass");
//自动添加css前缀  -webkit-
const autoprefixer = require('gulp-autoprefixer');
//抑制错误(出现错误时不会终止热更新线程)
const plumber = require('gulp-plumber');
//将scss编译成css
gulp.task("sass",function(){
	gulp.src("src/scss/**/*.scss")
		.pipe(plumber())
		.pipe(sass())
		.pipe(autoprefixer())
		.pipe(plumber.stop())
		.pipe(gulp.dest("src/css/"))
})
//压缩css代码
gulp.task("minify-css", function() {
	gulp.src("src/css/*.css")
		.pipe(CleanCss())
		.pipe(gulp.dest("dist/css"))
})
//复制HTML文件
gulp.task("copy-html", function() {
	gulp.src("src/**/*.html")
		.pipe(gulp.dest("dist/"))
})
//静态服务器
gulp.task('browser-sync', function() {
    browserSync.init({
        server: {
            baseDir: "./src"
        },
        port:8888
    });
    //热更新
    gulp.watch(["src/**/*.html", "src/css/**/*.css"],browserSync.reload)
    gulp.watch("src/scss/**/*.scss",["sass"]).on("change",browserSync.reload)
});